import axios from './rquest'

export const get = (url: any, params = {}) => {
  return new Promise((resove, reject) => {
    axios
      .get(url, { params })
      .then((res) => {
        resove(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export const post = (url: any, params = {}) => {
  return new Promise((resove, reject) => {
    axios
      .post(url, params)
      .then((res) => {
        resove(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

// delete与get的一样，put、patch与post的一样
// patch常用于更新数据
export const patch = (url: any, params = {}) => {
  return new Promise((resove, reject) => {
    axios
      .patch(url, params)
      .then((res) => {
        resove(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export const put = (url: any, params = {}) => {
  return new Promise((resove, reject) => {
    axios
      .put(url, params)
      .then((res) => {
        resove(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export const deletes = (url: any, params = {}) => {
  return new Promise((resove, reject) => {
    axios
      .delete(url, { params })
      .then((res) => {
        resove(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

// 批量删除
export const deleteAll = (url: any, params = {}) => {
  return new Promise((resove, reject) => {
    axios({
      method: 'delete',
      url,
      data: params,
      headers: {
        'content-type': 'application/json',
      },
    })
      .then((res) => {
        resove(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}
